home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / GNUST / !GNUst / st / MappedColl < prev    next >
Text File  |  1991-09-13  |  3KB  |  126 lines

  1. "======================================================================
  2. |
  3. |   MappedCollection Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     25 Apr 89      created.
  34. |
  35. "
  36.  
  37. Collection subclass: #MappedCollection
  38.        instanceVariableNames: 'domain map'
  39.        classVariableNames: ''
  40.        poolDictionaries: ''
  41.        category: nil.
  42.  
  43. MappedCollection comment: 
  44. 'I represent collections of objects that are indirectly indexed by names.
  45. There are really two collections involved: domain and a map.  The map maps
  46. between external names and indices into domain, which contains the
  47. real association.  In order to work properly, the domain and map objects must
  48. be instances of a subclass of SequenceableCollection or Dictionary. ' !
  49.  
  50. !MappedCollection class methodsFor: 'basic'!
  51.  
  52. collection: aCollection map: aMap
  53.     ^self new setCollection: aCollection andMap: aMap
  54. !
  55.  
  56. new
  57.     self error: 'new not available for MappedCollections; use collection:map:'
  58. !!
  59.  
  60.  
  61. !MappedCollection methodsFor: 'basic'!
  62.  
  63. at: key
  64.     ^domain at: (map at: key)
  65. !
  66.  
  67. at: key put: value
  68.     ^domain at: (map at: key) put: value
  69. !
  70.  
  71. contents
  72.     | contents |
  73.     contents _ Bag new.
  74.     map do: [ :domainKey | contents add: domain at: domainKey ].
  75.     ^contents
  76. !
  77.  
  78. size
  79.     ^domain size
  80. !
  81.  
  82. add: anObject
  83.     self shouldNotImplement
  84. !
  85.  
  86. contents
  87.     | aBag |
  88.     aBag _ Bag new.
  89.     map do: [ :value | aBag add: (domain at: value) ].
  90.     ^aBag
  91. !
  92.  
  93. do: aBlock
  94.     map do: [ :value | aBlock value: (domain at: value) ]
  95. !
  96.  
  97. collect: aBlock
  98.     | aStream |
  99.     aStream _ WriteStream on: (self species new: self size).
  100.     self do: [ :value | aStream nextPut: (aBlock value: value) ].
  101.     ^aStream contents
  102. !
  103.  
  104. select: aBlock
  105.     | aStream |
  106.     aStream _ WriteStream on: (self species new: self size).
  107.     self do: [ :value | (aBlock value: value) ifTrue:
  108.                 [ aStream nextPut: value ] ].
  109.     ^aStream contents
  110. !!
  111.  
  112.  
  113.  
  114. !MappedCollection methodsFor: 'private'!
  115.  
  116. setCollection: aCollection andMap: aMap
  117.     domain _ aCollection.
  118.     map _ aMap
  119. !
  120.  
  121. species
  122.     ^domain species
  123. !!
  124.